/*******************************************************************************
 * This file is part of blueprint4j www.blueprint4j.org.
 * 
 *     blueprint4j is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU Lesser General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 * 
 *     blueprint4j is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU Lesser General Public License for more details.
 * 
 *     You should have received a copy of the GNU Lesser General Public License
 *     along with blueprint4j. If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
/**
* This is an abstract message class no fields have been defined in this
* class
* $Log: Message.java,v $
* Revision 1.1.1.1  2004/04/22 12:56:14  travisb
* Fir
*
* Revision 1.1.1.1  2003/12/21 09:04:08  jaspervdb
* no message
*
* Revision 1.1.1.1  2003/10/20 15:30:48  travisb
* First import into CVS at Cellstop
*
* Revision 1.1.1.1  2003/03/30 15:25:28  tbulford
* no message
*
* Revision 1.1  2003/01/12 08:30:34  travis
* Import x MANY
*
* Revision 1.1.1.1  2002/12/16 22:14:01  jasper
* no message
*
* Revision 1.2  2002/09/29 17:17:14  travisb
* Template Processor Changes
*
* Revision 1.1  2002/02/20 13:30:43  JasperV
* First time add to new Applications layer
*
* Revision 1.1  2002/01/24 14:18:14  travisb
* First Version of the Application Layer
*
* Revision 1.1  2002/01/21 08:06:07  travisb
* First version commited to CVS
*
*/

package blueprint4j.messages;

import java.io.*;
import java.util.*;

public abstract class Message {

	/**
	* Sets all the message details from a properties file
	* @param props
	*/
	abstract public void setMessage(Properties props)
	throws ExceptionMessage ;


	/**
	* Returns all the message details in properties file
	* the properties are formatted as follows <br>
	*/
	abstract public Properties getMessage()
	throws ExceptionMessage;


	/**
	* Returns all the message details in properties string
	*/
	abstract public String getMessageAsString()
	throws ExceptionMessage;


	/**
	* Overloaded to return a more suitable name
	*/
	abstract public String toString();


	/**
	* Set this message name
	* @param
	*/
	abstract public void setName(String p_name);


	/**
	* Get this message name
	*/
	abstract public String getName();

	/**
	* Sets the message type
	*/
	abstract public void setType(String p_message_type ) throws ExceptionMessage;

	/**
	* Returns the message type
	*/
	abstract public String getType() throws ExceptionMessage;

	/**
	* Check is a field is defined
	* @param
	*/
	abstract public boolean hasField( int field )
	throws ExceptionMessage;


	/**
	* Check is a field is defined
	* @param
	*/
	abstract public boolean hasField( String field )
	throws ExceptionMessage;


	/**
	* Get the max width for the field
	* @param
	*/
	abstract public int getMaxFieldWidth( int field )
	throws ExceptionMessage;


	/**
	* Get the max width for the field
	* @param
	*/
	abstract public int getMaxFieldWidth( String field )
	throws ExceptionMessage;


	abstract public String get( int field_no )
	throws ExceptionMessage;

	abstract public String get( String field )
	throws ExceptionMessage;

	abstract public void set( int field_no, String p_value )
	throws ExceptionMessage;

	abstract public void set( String field, String p_value )
	throws ExceptionMessage;

	abstract public void setBinary( int field_no, byte[] p_value )
	throws ExceptionMessage ;

	abstract public void setBinary( String field, byte[] p_value )
	throws ExceptionMessage ;

	abstract public void read( InputStream input )
	throws ExceptionMessage, IOException;

	abstract public void write( OutputStream output )
	throws ExceptionMessage, IOException ;

	public void read(String data)
	throws ExceptionMessage, IOException {
		ByteArrayInputStream in=new ByteArrayInputStream(data.getBytes());
		read(in);
		in.close();
	}

	public String messageToString()
	throws ExceptionMessage, IOException {
		ByteArrayOutputStream out=new ByteArrayOutputStream();
		write(out);
		String value=new String(out.toByteArray());
		out.close();
		return value;
	}
}

